//
//  LeftViewController.m
//  SlideZoomMenuDemo
//
//  Created by renxiaojian on 15/3/16.
//  Copyright (c) 2015年 renxiaojian. All rights reserved.
//

#import "LeftViewController.h"
#import "AppDelegate.h"
#import "HomeViewController.h"
#import "MainViewController.h"
#import "LeftCell.h"
#import "FooTableViewController.h"
#import "LoginViewController.h"
#import "DSCommentViewController.h"
#import "DSHomeViewController.h"
#import "UIImageView+WebCache.h"
#import "DSUser.h"
#import "MoreViewController.h"
#import "FooTableViewController.h"
@interface LeftViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UILabel *name;

@property(nonatomic, strong) NSArray *titles;

@end

@implementation LeftViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    AVUser *user = [AVUser currentUser];
    self.name.text=user.username;
    AVFile *attachment=[user objectForKey:@"avatar"];
    NSString *urlStr=attachment.url;
    SDWebImageOptions options=SDWebImageRetryFailed|SDWebImageLowPriority;
    NSURL *url=[NSURL URLWithString:urlStr];
    [self.picImgView sd_setImageWithURL:url placeholderImage:nil options:options progress:^(NSInteger receivedSize, NSInteger expectedSize) {
        NSLog(@"下载进度:%f",(double)receivedSize/expectedSize);
    } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        NSLog(@"图片加载完毕:%@",image);
    }];
    self.titles = @[@"主页",@"宝宝圈",@"育儿食谱",@"每日记录",@"宝宝推荐",@"设置"];
    self.picImgView.layer.cornerRadius = 30;
    self.picImgView.layer.masksToBounds = YES;
    self.picImgView.backgroundColor = [UIColor blueColor];
    self.view.backgroundColor = [UIColor clearColor];
    self.tableView.backgroundColor = [UIColor clearColor];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerNib:[UINib nibWithNibName:@"LeftCell" bundle:nil] forCellReuseIdentifier:@"LeftCell"];
    [self performSelector:@selector(setupSlected) withObject:nil afterDelay:0.01];
   
}

- (void)setupSlected
{
     [self tableView:[self tableView] didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:self.selectedIndex inSection:0]];
    [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForItem:self.selectedIndex inSection:0] animated:NO scrollPosition:UITableViewScrollPositionNone];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.titles.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"LeftCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    cell.backgroundColor = [UIColor clearColor];
    cell.textLabel.font = [UIFont systemFontOfSize:16];
    cell.textLabel.text =[NSString stringWithFormat: @"%@",self.titles[indexPath.row]];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    AppDelegate *app = [UIApplication sharedApplication].delegate;
    if (indexPath.row == 4) {
        DSHomeViewController *homeVC = [[DSHomeViewController alloc] init];
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:homeVC];
        app.slider.rootViewController = nav;
    }
    else if(indexPath.row==0){
        MainViewController *mainVC = [[MainViewController alloc] init];
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:mainVC];
        app.slider.rootViewController = nav;
    }
//      else if (indexPath.row==3){
//        RootViewController *rootVC=[[RootViewController alloc]init];
//        UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:rootVC];
//        app.slider.rootViewController=nav;
//    }
    else if(indexPath.row==5){
        MoreViewController *moreVC=[[MoreViewController alloc]init];
        UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:moreVC];
        app.slider.rootViewController=nav;
    }else if (indexPath.row==2){
        FooTableViewController *footVC=[[FooTableViewController alloc]init];
        UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:footVC];
        app.slider.rootViewController=nav;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
   
}


@end
